import random

class PaySystem():
    count = 100
    oneMoney = 5000
    rate = 0.1
    def principalDouble(self):
        print('本金翻倍交易系统')
        flag = 0
        max_flag = 0
        principal = self.oneMoney
        money = 0
        for i in range(self.count):
            # 随机取出1或者0
            result = random.randint(0, 1)
            if result == 1:
                print('第%d次' % (i + 1) + '成功', '本金为%d' % principal)
                money = money + principal * self.rate
                flag = 0
                principal = self.oneMoney
            else:
                print('第%d次' % (i + 1) + '失败', '本金为%d' % principal)
                money = money - principal * self.rate
                flag = flag + 1
                principal = self.oneMoney * 2 ** flag
                if flag > max_flag:
                    max_flag = flag
                if max_flag >= 5:
                    break
            print('----交易第%d次----' % (i+1), '盈利为：%d' % money, '最大连续失败次数', max_flag)
